import socket
import threading

# Target server address and port
target = input("请输入目标服务器地址: ")
port = int(input("请输入目标服务器端口: "))
num_connections = int(input("Please enter the number of connections to establish: "))

# Define the connection function
def connect():
    try:
        # Create a socket and connect to the target address
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((target, port))
        print("Connected to", target)
    except Exception as e:
        print("Connection failed:", e)

# Establish the specified number of connections
for _ in range(num_connections):
    threading.Thread(target=connect).start()